/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entity.JobItems;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author owtee
 */
@Stateless
public class JobItemsFacade extends AbstractFacade<JobItems> {

    @PersistenceContext(unitName = "MSGPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public JobItemsFacade() {
        super(JobItems.class);
    }

    public List<JobItems> findByName(String itemName) {
        em.getEntityManagerFactory().getCache().evictAll();
        return em.createQuery("SELECT j FROM JobItems j WHERE j.itemName LIKE :itemName")
                .setParameter("itemName", itemName)
                .getResultList();
    }

    public List<JobItems> findByName(int start, int end, String itemName) {
        em.getEntityManagerFactory().getCache().evictAll();
        return em.createQuery("SELECT j FROM JobItems j WHERE j.itemName LIKE :itemName")
                .setFirstResult(start)
                .setMaxResults(end)
                .setParameter("itemName", itemName)
                .getResultList();
    }

    public List<JobItems> findByActiveFlag(boolean activeFlag) {
        em.getEntityManagerFactory().getCache().evictAll();
        return em.createQuery("SELECT j FROM JobItems j WHERE j.activeFlag = :activeFlag")
                .setParameter("activeFlag", activeFlag)
                .getResultList();
    }
}
